package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.domain.entity.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

//    @Select("select distinct p.* from product p" +
//            " left join product_supplier ps on p.id=ps.product_id " +
//            " left join supplier s on s.id=ps.supplier_id " +
//            " ${ew.customSqlSegment}") //由QueryWrapper转换
//    @Results({@Result(id = true, property = "id", column = "id"),
//            @Result(property = "supplierList", column = "id",
//                    many = @Many(select = "edu.whu.demo.dao.SupplierDao.findSuppliersByProduct"))})
//    public IPage<Product> findProductsBySupplier(IPage<Product> page, @Param(Constants.WRAPPER) QueryWrapper<Product> wrapper);

    @Select("select distinct a.*,c.name as categoryName,t.name as typeName"  +
            " from article a" +
            " left join category c on a.category_id=c.id" +
            " left join type t on a.type_id=t.id" +
            " ${ew.customSqlSegment}")
    @Results({@Result(id = true, property = "categoryName",column = "categoryName"),
            @Result(property = "typeName",column = "typeName")})
    public IPage<Article> getArticlePage(IPage<Article> page, @Param(Constants.WRAPPER)QueryWrapper<Article> qw);

    @Select("select * from article WHERE type_id=0")
    public List<Article> getLatestBaike();

    @Select("select * from article where type_id=0 order by view_count desc limit 3")
    public List<Article> getBrowseList();
}
